//
//  MainTabBar.m
//  rabbit微博
//
//  Created by mac on 15/12/13.
//  Copyright © 2015年 mac. All rights reserved.
//

#import "MainTabBar.h"

@implementation MainTabBar


- (instancetype)init
{
    self = [super init];
    
    //添加加号按钮
    [self addSubview:self.plusBtn];
    
    return self;
}

#pragma mark --- 重新设置按钮的frame
- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat w = self.bounds.size.width / 5;
    CGFloat h = self.bounds.size.height;
    CGRect rect = CGRectMake(0, 0, w, h);

    CGFloat index = 0;

    for (UIView *subview in self.subviews)
    {
        if ([subview isKindOfClass:NSClassFromString(@"UITabBarButton")])
        {
            subview.frame = CGRectOffset(rect, w * index, 0);
            
            index += (index == 1 ? 2 : 1);
        }
    }
    
    self.plusBtn.frame = CGRectOffset(rect, w * 2, 0);
}



//l懒加载加号按钮，设置属性
- (UIButton *)plusBtn
{
    if(_plusBtn == nil)
    {
        _plusBtn = [[UIButton alloc] init];
        
        [_plusBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        
        [_plusBtn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add_highlighted"] forState:UIControlStateHighlighted];
        
        [_plusBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];
        
        [_plusBtn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        
        [_plusBtn sizeToFit];
        
    }
        return _plusBtn;
}

@end
